package com.oa.demo.auth.manager;

import com.oa.demo.auth.entity.TMenu;
import com.oa.demo.auth.entity.TUser;
import com.oa.demo.auth.mapper.TMenuMapper;
import com.oa.demo.auth.mapper.TUserMapper;
import com.sun.javafx.binding.StringConstant;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 业务类
 * @author 孔德成
 * @date 2020/11/27 13:54
 */
@Service
public class UserManager {

    @Autowired
    private TUserMapper userMapper;
    @Autowired
    private TMenuMapper menuMapper;


    public TUser findByName(String username) {
        TUser user = userMapper.findByName(username);
        if (user!=null){

        }
        return user;
    }

    public String findUserPermissions(Integer id) {
        List<TMenu> userPermissions = menuMapper.findUserPermissions(id);

        List<String> perms = new ArrayList<>();
        for (TMenu m: userPermissions){
            perms.add(m.getMenuUrl());
        }
        return StringUtils.join(perms, ",");
    }
}
